#include "comm.h"
#include "sys/ipc.h"
#include "sys/shm.h"
#include "sys/types.h"
#include "unistd.h"


int main() {
    key_t key = ftok(PATH_NAME, PROJ_ID);
    if (key < -1 ) {
        perror("ftok");
        return 1;
    }  
   
    // 获取共享内存
    int shmid = shmget(key, SIZE, IPC_CREAT);
    if (shmid < 0) {
        perror("shmget");
        return 2;
    }

    // 将当前进程关联到获取到的共享内存
    char *shmaddr = (char *)shmat(shmid, NULL, 0);

    // 通信
    //sleep(10);
    char c = 'A';
    while (c <= 'Z') {
        shmaddr[c - 'A'] = c;
        c++;
        sleep(2);
    }


    // 去关联
    shmdt(shmaddr);

    printf("%x\n", key);

}
